package com.ton.config.annotation.admin;

import com.ton.common.entity.SystemUser;
import com.ton.utils.auth.AuthUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @program: js-hd
 * @description: 管理员鉴权切面
 * @author: yyf
 * @create: 2024-01-29 16:57
 **/
@Aspect
@Slf4j
@Component
@AllArgsConstructor
public class AdminAspect {
    @Autowired
    private AuthUtil authUtil;
//    @Autowired
//    private UserService userService;
    @Pointcut("@annotation(com.ton.config.annotation.admin.Admin)")
    private void annotationPointCut(){

    }

    @Around("annotationPointCut() && @annotation(admin)")
    public Object before(ProceedingJoinPoint joinPoint, Admin admin) throws Throwable {
        SystemUser user = authUtil.getUser();
        if(user.getAccountType()!=9){
            throw new RuntimeException("管理员才能访问");
        }
        return joinPoint.proceed();
    }

}
